// pages/supplier_information/supplier_information.js
import basesup from '~/utils/supplier.js'
import baseteam from '~/utils/teamleader.js'
// collectrecord
Page({

    /**
     * 页面的初始数据
     */
    data: {
        aac4:'#FFFFFF',
        settop:0,

        ismy:0,
        companyid:'',

        companyitem:{}
    },
    naveback(){
        setTimeout(() => {
            wx.navigateBack()
        }, 300);
    },
    // 跳转店铺
    gotoShop(){
      wx.navigateTo({
        url: `../../pages/shophomepage/shophomepage?id=${this.data.companyid}`,
    })
    },
    navenext() {
        console.log(this.data.companyid)
        wx.navigateTo({
            url: `../../pages/shophomepage/shophomepage?id=${this.data.companyid}`,
        })
    },
    async getcompanyitem() {
        let reqdata = {
            storeId:this.data.companyid
        }
        let resdatas = await basesup.companyitem(reqdata)
        console.log('resdatass',resdatas)
        this.setData({
            companyitem: resdatas.data.data.item,
            ismy:resdatas.data.data.my
        })
        console.log('companyitem',this.data.companyitem);
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let Bartop = (0, wx.getMenuButtonBoundingClientRect)().top;
        let BarHeight = (0, wx.getMenuButtonBoundingClientRect)().height;
        this.setData({
            settop: Bartop + BarHeight * 1.5
        })


        if (JSON.stringify(options) != undefined && JSON.stringify(options).length > 2) {
            this.setData({
                companyid: options.id
            })
            this.getcompanyitem()
        } else {
            wx.showToast({
                title: '查询失败',
                icon: 'none',
                duration: 2000
            })
            setTimeout(() => {
                this.naveback()
            }, 2000);
        }


    },
    nextcard(){
        wx.navigateTo({
          url: '../supplier_card/supplier_card?id='+this.data.companyid,
        })
    },

    async collstart(){
        let reqdata = {
            storeId:this.data.companyid
        }
        let resdata = await baseteam.appletstore(reqdata)
        if (resdata.code == 200) {
            wx.showToast({
                title: '操作成功',
                icon: 'none',
                duration: 2000
            })
            this.getcompanyitem()
        }else{
            wx.showToast({
                title: '操作失败，请重试！',
                icon: 'error',
                duration: 2000
            })
        }
    },
    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})